package com.andon.microcellsimulator.model;

import android.content.Context;
import android.content.SharedPreferences;

public class GlobalBeanManager {

    private static final String PREF = "login_info";

    // GlobalBean
    private static GlobalBean globalBean;

    private static SharedPreferences spref;

    private GlobalBeanManager() {
    }

    public static GlobalBean getGlobalBean() {

//        if (globalBean == null) {
//            spref = context.getSharedPreferences(PREF, Context.MODE_PRIVATE);
//
//            globalBean = new GlobalBean();
//            globalBean.setDeviceID(spref.getString("DeviceID", ""));
//            globalBean.setRsa(spref.getString("RSA", ""));
//            globalBean.setAccessToken(spref.getString("AccessToken", ""));
//            globalBean.setAccessExpire(spref.getInt("AccessExpire", 0));
//        }

        if (globalBean == null) {
            globalBean = new GlobalBean();
        }

        return globalBean;
    }

    public static void setGlobalBean(GlobalBean globalBean) {

        GlobalBeanManager.globalBean = globalBean;

//        if (context != null) {
//            SharedPreferences.Editor editor = context.getSharedPreferences(PREF, Context.MODE_PRIVATE).edit();
//
//            if (globalBean == null) {
//                editor.putString("DeviceID", "");
//                editor.putString("RSA", "");
//                editor.putInt("AccessExpire", 0);
//                editor.putString("AccessToken", "");
//            } else {
//                editor.putString("DeviceID", globalBean.getDeviceID());
//                editor.putString("RSA", globalBean.getRsa());
//                editor.putInt("AccessExpire", globalBean.getAccessExpire());
//                editor.putString("AccessToken", globalBean.getAccessToken());
//            }
//
//            editor.apply();
//        }

    }

}